<div class="form">
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'suppliers-form',
	'enableAjaxValidation'=>false,
        'method'=>'post',
	'type'=>'horizontal',
	'htmlOptions'=>array(
		'enctype'=>'multipart/form-data'
	)
)); ?>

<div id="tabs">
	<ul id="tab-head" class="nav nav-tabs">
		<li class="active"><a data-toggle="tab" href="#tab1">Vendor Information</a></li>
		<li class=""><a data-toggle="tab" href="#tab2">Contact Person</a></li>
	</ul>
	<div class="tab-content">
		<div id="tab1" class="tab-pane fade active in">
				<fieldset>
				<legend>
					<p class="note">Fields with <span class="required">*</span> are required.</p>
				</legend>

			<?php echo $form->errorSummary($model,'Opps!!!', null,array('class'=>'alert alert-error span12')); ?>
						
		   <div class="control-group">		

			<div class="span4">
			<?php echo $form->textFieldRow($model,'supplier_code',array('class'=>'span3','maxlength'=>255)); ?>

			<?php echo $form->textFieldRow($model,'name',array('class'=>'span3','maxlength'=>-1)); ?>

			<?php echo $form->textAreaRow($model,'address',array('class'=>'span3','maxlength'=>-1)); ?>

			<?php echo $form->textFieldRow($model,'city',array('class'=>'span3','maxlength'=>-1)); ?>

			<?php echo $form->textFieldRow($model,'post_code',array('class'=>'span3','maxlength'=>-1)); ?>
			
			<?php echo $form->textFieldRow($model,'phone_number',array('class'=>'span3','maxlength'=>-1)); ?>

			
			</div>
			<div class="span4 last">
			

			<?php echo $form->textFieldRow($model,'fax',array('class'=>'span3','maxlength'=>-1)); ?>
			
			<?php echo $form->textFieldRow($model,'email',array('class'=>'span3','maxlength'=>255)); ?>

			<?php echo $form->textFieldRow($model,'website',array('class'=>'span3','maxlength'=>255)); ?>

			<?php echo $form->textFieldRow($model,'npwp',array('class'=>'span3','maxlength'=>-1)); ?>

			<?php echo $form->textFieldRow($model,'attn',array('class'=>'span3','maxlength'=>-1)); ?>

			<?php echo $form->textFieldRow($model,'cc',array('class'=>'span3','maxlength'=>-1)); ?>
			</div>

			</div>
			</fieldset>
	   </div>
		<div id="tab2" class="tab-pane fade">
		<table id="test" class="items table table-striped table-bordered table-condensed">
		<thead>
		<th width="30">No</th>
		<th>Name</th>
		<th>Phone</th>
		<th>Handphone</th>
		<th>Email</th>
		<th>Position</th>
		<th width="30">Action</th>
		</thead>
		<tbody>
		<tr> 
		            <td colspan="7" id="addVar">Add Variable</td>
		            
		</tr>
		</tbody>
		</table>

	
     
		
		</div>
	</div>
</div>


     	

	<div class="form-actions">
		<?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'submit',
			'type'=>'primary',
                        'icon'=>'ok white',  
			'label'=>$model->isNewRecord ? 'Create' : 'Save',
		)); ?>
              <?php $this->widget('bootstrap.widgets.TbButton', array(
			'buttonType'=>'reset',
                        'icon'=>'remove',  
			'label'=>'Reset',
		)); ?>
	</div>


<?php $this->endWidget(); ?>

</div>


		           

	

		
		<script>!window.jQuery && document.write('<script src="js/jquery-1.7.2.min.js"><\/script>')</script>
<?php if($model->isNewRecord){ ?>
	<script>
	//initialize with 3
	var startingNo = 0;
	var $node = "";
	for(varCount=0;varCount<=startingNo;varCount++){
		var displayCount = varCount+1;
		$node += '<tr id="teer_'+displayCount+'"><td>'+displayCount+'</td><td id="dihap'+displayCount+'"><input type="text" name="nama[]"/></td><td><input type="text" name="position[]"/></td><td><input type="text" name="phone[]"/></td><td><input type="text" name="handphone[]"/></td><td><input type="text" name="email[]"/></td><td><span onClick="testing('+displayCount+')" class="removeVar">X</span></td></tr>';
	}
	$('#test').prepend($node);
	
	function testing(nilai){
		$("#teer_"+nilai).remove();
	}

	$('#addVar').on('click', function(){
		//new node
		varCount++;
		$node = '<tr id="teer_'+varCount+'"><td>'+varCount+'</td><td id="dihap'+varCount+'"><input type="text" name="nama[]"/></td><td><input type="text" name="position[]"/></td><td><input type="text" name="phone[]"/></td><td><input type="text" name="handphone[]"/></td><td><input type="text" name="email[]"/></td><td><span onClick="testing('+varCount+')" class="removeVar">X</span></td></tr>';
		$(this).parent().before($node);
	});
	
	
	</script>
	
<?php }else{ ?>
	<script>
	//initialize with 3
	var startingNo = 0;
	var $node = "";
	
		
		<?php 
		$dataContact = SupplierContacts::model()->findAll("supplier_code='".$model->supplier_code."'");
		$j=0; 
		
		?>
		for(varCount=0;varCount<=startingNo;varCount++){
		var displayCount = varCount+<?php echo count($dataContact); ?>-1;
		$node += '<?php foreach($dataContact as $dat): ?><tr id="teer_<?php echo $j+1; ?>"><td><?php echo $j+1; ?></td><td id="dihap<?php echo $j+1; ?>"><input type="text" value="<?php echo $dat->name; ?>" name="nama[]"/></td><td><input type="text" name="position[] value="<?php echo $dat->position; ?>""/></td><td><input type="text" name="phone[] value="<?php echo $dat->phone; ?>""/></td><td><input type="text" name="handphone[] value="<?php echo $dat->handphone; ?>""/></td><td><input type="text" name="email[]" value="<?php echo $dat->email; ?>"/></td><td><span onClick="testing(<?php echo $j+1; ?>)" class="removeVar">X</span></td></tr><?php $j++; endforeach; echo $j; ?>';
	}
	function testing(nilai){
		$("#teer_"+nilai).remove();
	}
	$('#test').prepend($node);
	
	
	$('#addVar').on('click', function(){
		//new node
		
		varCount++;
		$node = '<tr id="teer_'+(parseInt(varCount)+<?php echo count($dataContact)-1; ?>)+'"><td>'+(parseInt(varCount)+<?php echo count($dataContact)-1; ?>)+'</td><td id="dihap'+(parseInt(varCount)+<?php echo count($dataContact)-1; ?>)+'"><input type="text" name="nama[]"/></td><td><input type="text" name="position[]"/></td><td><input type="text" name="phone[]"/></td><td><input type="text" name="handphone[]"/></td><td><input type="text" name="email[]"/></td><td><span onClick="testing('+(parseInt(varCount)+<?php echo count($dataContact)-1; ?>)+')" class="removeVar">X</span></td></tr>';
		$(this).parent().before($node);
	});
	
	
	</script>
<?php } ?>